import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login.vue'
import store from '../store'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/Register.vue'),
    },
    {
      path: '/',
      name: 'home',
      component: () => import('../views/Home.vue'),
      redirect: '/welcome',
      children: [
        {
          path: '/welcome',
          name: 'welcome',
          component: () => import('../views/Welcome.vue')
        },
        {
          path: '/article-classify',
          name: 'article-classify',
          component: () => import('../views/ArticleClassify.vue')
        },
        {
          path: '/article-list',
          name: 'article-list',
          component: () => import('../views/ArticleList.vue')
        },
        {
          path: '/user-information',
          name: 'user-information',
          component: () => import('../views/UserInformation.vue')
        },
        {
          path: '/set-head-portrait',
          name: 'set-head-portrait',
          component: () => import('../views/SetHeadPortrait.vue')
        },
        {
          path: '/reset-password',
          name: 'reset-password',
          component: () => import('../views/ResetPassword.vue')
        },
        {
          path: '/article-add',
          name: 'article-add',
          // props: true,
          component: () => import('../views/ArticleAdd.vue')
        },
        {
          path: '/video-add',
          name: 'video-add',
          // props: true,
          component: () => import('../views/VideoAdd.vue')
        },
      ]
    },
  ]
})

// 路由前置守卫
// router.beforeEach((to, from, next) => {
//   // 保存菜单激活状态
//   store.commit('setActivePath', to.name)
//   // 页面权限控制
//   if (to.name !== 'login' && !window.localStorage.getItem('token')) next({ name: 'login' })
//   else next()
// })

export default router
